<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\Node;
use Illuminate\Http\Request;
use App\Http\Controllers\Admin\BaseController;
class NodeController extends BaseController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

        $data=(new Node())->getNodeAll();

        return view('admin.node.index',compact('data'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //节点添加 需要全部权限
        $data=(new Node())->getNodeAll();
        return view('admin.node.create',compact('data'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $params=$request->except('_token');
     //   dd($params);
       $res= Node::create($params);
       if ($res){

           return $this->writeJson(0,"","添加成功");
       }else{
           return $this->writeJson(12220,"","添加失败");
       }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $data=(new Node())->getNodeAll();
        $nodeInfo = Node::find($id);

        return view('admin.node.edit',compact('nodeInfo','data'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Node $node)
    {
      /*  $data =$request->except('_token');
        dd($data);*/
        // 没有修改执行
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {

       $res =Node::destroy($id);

     if ($res){


         return  $this->writeJson(0,null,'删除成功');
     }else{


         return  $this->writeJson(111011,null,'删除失败');

     }
    }
}
